package com.martin.lib_base.ui.screen

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.contentColorFor
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.window.DialogProperties

/**
 * @author：孟凡华
 * @date：2023/6/29
 * @desc：
 */

/**
 * 通用的AlertDialog
 */
@Composable
fun CommonAlertDialog(
    show: Boolean,
    onDismissRequest: () -> Unit,
    title: @Composable (() -> Unit)? = null,
    content: @Composable (() -> Unit)? = null,
    confirmButton: @Composable () -> Unit = { CommonDialogButton() { onDismissRequest() } },
    dismissButton: @Composable (() -> Unit)? = { CommonDialogButton("取消") { onDismissRequest() } },
    modifier: Modifier = Modifier,
    shape: Shape = MaterialTheme.shapes.large,
    backgroundColor: Color = MaterialTheme.colorScheme.surface,
    properties: DialogProperties = DialogProperties()
) {
    if (show) {
        AlertDialog(
            onDismissRequest = {
                onDismissRequest()
            },
            confirmButton = confirmButton,
            dismissButton = dismissButton,
            title = title,
            text = content,
            modifier = modifier,
            shape = shape,
            containerColor = backgroundColor,
            properties = properties,
        )
    }

}

@Composable
fun CommonDialogButton(text: String = "确认", onClick: () -> Unit) {
    TextButton(onClick = {
        onClick()
    }) {
        Text(text = text)
    }
}

/**
 * 通用标题
 */
@Composable
fun CommonDialogTitle(title: String) {
    Text(
        text = title,
        style = MaterialTheme.typography.titleMedium,
    )
}

/**
 * 通用内容
 */
@Composable
fun CommonDialogContent(content: String) {
    Text(
        text = content,
        style = MaterialTheme.typography.bodyMedium,
    )
}